﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using des = KingsSharp.Common.Secutiry;

namespace Jwell.DesHelper
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void jiamibtn_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(miyao.Text))
            {
                MessageBox.Show("加密密钥不能为空字符串，请输入！");
            }
            else if (miyao.Text.Length != 8 && miyao.Text.Length != 24)
            {
                MessageBox.Show("密钥长度必须为8位或24位");
            }
            else if (string.IsNullOrWhiteSpace(shurubox.Text))
            {
                MessageBox.Show("需要加密的内容不能为空，请输入！");
            }
            else
            {
                string result = des.DesHelper.Encrypt(shurubox.Text, miyao.Text);
                shuchubox.Text = result;
            }
        }

        private void jiemibtn_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(miyao.Text))
            {
                MessageBox.Show("解密密钥不能为空字符串，请输入！");
            }
            else if (miyao.Text.Length != 8 && miyao.Text.Length != 24)
            {
                MessageBox.Show("密钥长度必须为8位或24位");
            }
            else if (string.IsNullOrWhiteSpace(shurubox.Text))
            {
                MessageBox.Show("需要解密的内容不能为空，请输入！");
            }
            else
            {
                string result = des.DesHelper.Decrypt(shurubox.Text, miyao.Text);
                shuchubox.Text = result;
            }
        }
    }
}
